from Tkinter import*
root = Tk()
c_= Canvas(root,height=760,width=720)
c_.pack()
f_ = open("input","r")
def readline_():
	global split_
	line_ = f_.readline()
	split_ = line_.split()
def two_notes_up():
	global y,line,scl,x
	c_.create_oval(x[i],y[0]+line,x[i]+scl,y[0]+line+scl,fill="black")
	c_.create_oval(x[i+1],y[1]+line,x[i+1]+scl,y[1]+line+scl,fill="black")
	c_.create_line(x[i]+scl,y[0]+line,x[i]+scl,y[0]+line-scl*3)
	c_.create_line(x[i+1]+scl,y[1]+line,x[i+1]+scl,y[1]+line-scl*3)
	c_.create_line(x[i]+scl,y[0]+line-scl*3,x[i+1]+scl,y[1]+line-scl*3,width = 2)
def two_notes_d():
	global y,line,scl,x
	c_.create_oval(x[i],y[0]+line,x[i]+scl,y[0]+line+scl,fill="black")
	c_.create_oval(x[i+1],y[1]+line,x[i+1]+scl,y[1]+line+scl,fill="black")
	c_.create_line(x[i],y[0]+line,x[i],y[0]+line+scl*4)
	c_.create_line(x[i+1],y[1]+line,x[i+1],y[1]+line+scl*4)
	c_.create_line(x[i],y[0]+line+scl*4,x[i+1],y[1]+line+scl*4,width = 2)
def chetv_d():
	global y,line,scl,x,nota
	c_.create_oval(x[i],nota+line,x[i]+scl,nota+line+scl,fill="black")
	c_.create_line(x[i],nota+line,x[i],nota+line+scl*4)
def pol_d():
	global y,line,scl,x,nota
	c_.create_oval(x[i],nota+line,x[i]+scl,nota+line+scl)
	c_.create_line(x[i],nota+line,x[i],nota+line+scl*4)
def cel():
	global y,line,scl,x,nota
	c_.create_oval(x[i],nota+line,x[i]+scl,nota+line+scl)
def chetv_d_t():
	global y,line,scl,x,nota
	c_.create_oval(x[i],nota+line,x[i]+scl,nota+line+scl,fill="black")
	c_.create_oval(x[i]+scl*1.6,nota+line+scl/2,x[i]+scl*2,nota+line+scl/1.3,fill="black")
	c_.create_line(x[i],nota+line,x[i],nota+line+scl*4)
def single_d():
	global y,line,scl,x,nota
	c_.create_oval(x[i],nota+line,x[i]+scl,nota+line+scl,fill="black")
	c_.create_line(x[i],nota+line,x[i],nota+line+scl*4)
	c_.create_line(x[i],nota+line+scl*4,x[i]+scl/2,nota+line+scl*2)
def stan_():
	global y,line,scl,x,nota
	si = 0
	for st in range(line-int(scl*1.5),line+scl*9,scl):
		si += 1
		if si <= 3:
			c_.create_line(0,st,720,st,dash=(2, 4))
		elif si >= 9:
			c_.create_line(0,st,720,st,dash=(2, 4))
		else:	
			c_.create_line(0,st,720,st)
def obrab_():
	global i,scl,notes,line,x,y,nota
	randomfont="Purisa"
	scl = 10
	line = scl*10
	i = 0
	[a,g,f,e,d,c,B,A,G,F,E,D,C] = range(0,65,scl/2)
	notes = [C,D,E,F,G,A,B,c,d,e,f,g,a]
	y = notes
	x = range(15,705,int(scl*3))
	for eli in split_:
		print eli
		if eli == "r2":
			y = [B]
			c_.create_text(x[i],y[0]+line,font=(randomfont,14),text=eli)
			i += 1
			continue
		elif eli == "||":
			y = [e,E]
			c_.create_line(x[i],y[0]+line,x[i],y[1]+line)
			c_.create_line(x[i]+scl/2,y[0]+line,x[i]+scl/2,y[1]+line,width = 4)
			i += 1
			continue
		elif eli == "Ac":
			y = [A,c]
			two_notes_up()
			i += 2
			continue
		elif eli == "Bc":
			y = [B,c]
			two_notes_up()
			i += 2
			continue
		elif eli == "dc":
			y = [d,c]
			two_notes_d()
			i += 2
			continue
		for eli in eli:
			if eli == "e":
				nota = e
			elif eli == "d":
				nota = d
			elif eli == "A":
				nota = A
			elif eli == "1":
				single_d()
				i += 1
			elif eli == "2":
				chetv_d()
				i += 1
			elif eli == "3":
				chetv_d_t()
				i += 1
			elif eli == "4":
				pol_d()
				i += 1
			elif eli == "8":
				cel()
				i += 1
			elif eli == "|":
				y = [e,E]
				c_.create_line(x[i],y[0]+line,x[i],y[1]+line)
				i += 1
readline_()
obrab_()
stan_()
root.mainloop()
